package com.jy.api.controller.common;

import com.jy.api.dao.CouponDao;
import com.jy.api.dao.StoreDao;
import com.jy.api.domain.Coupon;
import com.jy.api.domain.CouponInstance;
import com.jy.api.domain.Store;
import com.jy.api.service.WechatTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by lihu on 2018/3/24.
 */
@RequestMapping(value = "/v1/instance", produces = "application/json;charset=utf-8")
@RestController
public class CommonInstanceController {


    @Autowired
    StoreDao storeDao;

    @Autowired
    CouponDao couponDao;

    @Autowired
    WechatTemplateService wechatTemplateService;

    /**
     * 优惠卷过期提醒
     *
     * @param instance
     */
    @RequestMapping(value = "/remind", method = RequestMethod.POST)
    public ResponseEntity sendRemind(@RequestBody CouponInstance instance) {
        Store store = storeDao.findOne(instance.getStoreId());
        Coupon coupon = couponDao.findOne(instance.getCouponId());
        wechatTemplateService.sendCardOverdue(instance, coupon, store);
        return new ResponseEntity(HttpStatus.OK);
    }
}
